package ThreadTest;

import org.junit.Test;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created with LXD
 *
 * @author:Luhui
 * @qq:729913162
 * @Date:2018-08-12
 * @Time:17:57
 */
public class Thread2 {
    @Test
    public void async() throws ExecutionException, InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        executorService.submit(()->{
            try {
                Thread.sleep(2000);
                System.out.println("ok");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        executorService.submit(()->{
            try {
                Thread.sleep(5000);
                System.out.println("ok");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        executorService.shutdown();
        CountDownLatch doneSignal = new CountDownLatch(1);
        doneSignal.await();
        System.out.println("hello");
        System.out.println();
        System.out.println("执行完成");
    }
}
